package org.example.lys.stream;

import org.example.lys.json.JsonUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author liyishan
 * @date 2023/6/21 10:53
 * @apiNote
 */

public class testBasic {
    public static void main(String[] args) {
        List<String> ids = build();
        test4(ids);
    }

    private static void test1 (List<String> ids){
        List<String> result = ids.stream().filter(Objects::nonNull).collect(Collectors.toList());
        System.out.println(JsonUtils.toJson(result));
    }


    private static void test2(List<String> ids){
        List<Integer> result = ids.stream().filter(Objects::nonNull).map(Integer::parseInt).collect(Collectors.toList());
        System.out.println(JsonUtils.toJson(result));

    }

    private static void test3(List<String> ids){
        Boolean flag = ids.stream().anyMatch("11"::equals);
        System.out.println(flag);
    }

    /**
     * 取交集
     * @param ids
     */
    private static void test4(List<String> ids){
        List<String> listType = new ArrayList<>();
        listType.add("11");
        List<String> result= ids.stream().filter(listType::contains).collect(Collectors.toList());
        System.out.println(JsonUtils.toJson(result));
    }


    private static List<String> build(){
        List<String> ids = new ArrayList<>();
        ids.add("11");
        ids.add(null);
        return ids;
    }



}
